import grails.util.GrailsUtil
import hotsaucerecipes.Recipe
import hotsaucerecipes.Review
import hotsaucerecipes.User

class BootStrap {

    def init = { servletContext ->
        switch (GrailsUtil.environment) {
            case "development":

                def admin = new User(login: "admin",
                        password: "wordpass",
                        role: "admin")

                admin.save()

                if (admin.hasErrors()) {
                    println admin.errors
                }

                def jdoe = new User(login: "jdoe",
                        password: "password",
                        role: "user")

                jdoe.save()
                if (jdoe.hasErrors()) {
                    println jdoe.errors
                }

                def chixDip = new Recipe(title: "Buffalo Chicken Dip",
                        ingredients: """2 (10 ounce) cans chunk chicken, drained
                                            2 (8 ounce) packages cream cheese, softened
                                            1 cup Ranch dressing
                                            3/4 cup pepper sauce (such as Frank's Red Hot®)
                                            1 1/2 cups shredded Cheddar cheese
                                            1 bunch celery, cleaned and cut into 4 inch pieces
                                            1 (8 ounce) box chicken-flavored crackers""",
                        instructions: """Heat chicken and hot sauce in a skillet over medium heat, until
                                           heated through. Stir in cream cheese and ranch dressing. Cook, stirring
                                           until well blended and warm. Mix in half of the shredded cheese, and
                                           transfer the mixture to a slow cooker. Sprinkle the remaining cheese over
                                           the top, cover, and cook on Low setting until hot and bubbly.
                                           Serve with celery sticks and crackers.""")
                chixDip.save()
                if (chixDip.hasErrors()) {
                    println chixDip.errors
                }

                def chixWings = new Recipe(title: "Buffalo Chicken Wings",
                                    ingredients: """1/2 cup all-purpose flour
                                            1/4 teaspoon paprika
                                            1/4 teaspoon cayenne pepper
                                            1/4 teaspoon salt
                                            10 chicken wings
                                            oil for deep frying
                                            1/4 cup butter
                                            1/4 cup hot sauce
                                            1 dash ground black pepper
                                            1 dash garlic powder""",
                                    instructions: """In a small bowl mix together the flour, paprika, cayenne pepper 
                                            and salt. Place chicken wings in a large nonporous glass dish or bowl and 
                                            sprinkle flour mixture over them until they are evenly coated. Cover dish 
                                            or bowl and refrigerate for 60 to 90 minutes. Fry coated wings in hot oil 
                                            for 10 to 15 minutes, or until parts of wings begin to turn brown. Remove 
                                            from heat, place wings in serving bowl, add hot sauce mixture and stir 
                                            together. Serve.""")
                chixWings.save()
                if(chixWings.hasErrors()) {
                    println chixWings.errors
                }

                def rev = new Review(title: "So good!",
                        comments: "Don't skimp on the hot sauce.",
                        rating: 5,
                        recipe: chixDip)
                rev.save()
                if (rev.hasErrors()) {
                    println rev.errors
                }

                def rev2 = new Review(title: "Meh.",
                        comments: "Limp wristed with the hot sauce",
                        rating: 2,
                        recipe: chixDip)
                rev2.save()
                if (rev2.hasErrors()) {
                    println rev2.errors
                }

                def rev3 = new Review(title: "Sooooooo tasty!",
                        comments: "Sooooooooo spicy!",
                        rating: 5,
                        recipe: chixWings)
                rev3.save()
                if (rev3.hasErrors()) {
                    println rev3.errors
                }

                def rev4 = new Review(title: "Where's the buffalo?",
                        comments: "These are chicken wings, not buffalo. le sigh.",
                        rating: 1,
                        recipe: chixWings)
                rev4.save()
                if (rev4.hasErrors()) {
                    println rev4.errors
                }

                break//development

            case "production": break
        }
    }
    def destroy = {
    }
}
